﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using KenLib.BusinessManager;

public partial class APP_frmA_CompBranchList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = @"所属組合員企業一覧";
        ((APP_MasterPage_appCom)this.Master).changeTitle("所属組合員企業一覧");
        ((APP_MasterPage_appCom)this.Master).HideLiArea("frmA_CompBranchList");
        if (!IsPostBack)
        {
            //Show本社情報();// show gridview.
        }
        if (Session["役"] == null)
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        else if (Session["役"].ToString() == "1")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        set_本社情報();// hien thi danh sach cac cong ty dang truc tiep thuoc va hiep hoi hien tai.
        Show本社情報();
        
    }

    public void set_本社情報()// hien thi danh sach cac cong ty dang truc tiep thuoc va hiep hoi hien tai.
    {
        try
        {
            本社情報Manager frm = new 本社情報Manager();
            本社情報 obj = new 本社情報();
            obj.企業ID = Int32.Parse(Session["企業コード_2"].ToString());
            DataTable dt = new DataTable();
            dt = frm.get_本社情報(obj);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].ToString() != "")
                {
                    lbl_監理団体名.Text = dt.Rows[0][0].ToString();
                }
                else
                {
                    lbl_監理団体名.Text = "-";
                }
                if (dt.Rows[0][1].ToString() != "")
                {
                    string date = dt.Rows[0][1].ToString();
                    DateTime date1 = DateTime.Parse(date);
                    date = date1.ToString("yyyy年MM月dd日");
                    lbl_設立年月日.Text = date;
                }
                else
                {
                    lbl_設立年月日.Text = "-";
                }

                if (dt.Rows[0][2].ToString() != "")
                {
                    Label3.Text = dt.Rows[0][2].ToString();
                }
                else
                {
                    Label3.Text = "-";
                }

                if (dt.Rows[0][3].ToString() != "")
                {
                    lbl_資本金.Text = Convert.ToDecimal(dt.Rows[0][3]).ToString("###,###") + " 円";
                }
                else
                {
                    lbl_資本金.Text = "-";
                }


                if (dt.Rows[0][4].ToString() != "")
                {
                    lbl_郵便番号.Text = dt.Rows[0][4].ToString();
                }
                else
                {
                    lbl_郵便番号.Text = "-";
                }
                if (dt.Rows[0][5].ToString() != "")
                {
                    lbl_住所.Text = dt.Rows[0][5].ToString();
                }
                else
                {
                    lbl_住所.Text = "-";
                }
                if (dt.Rows[0][6].ToString() != "")
                {
                    lbl_電話番号.Text = dt.Rows[0][6].ToString();
                }
                else
                {
                    lbl_電話番号.Text = "-";
                }
                if (dt.Rows[0][7].ToString() != "")
                {
                    lbl_FAX番号.Text = dt.Rows[0][7].ToString();
                }
                else
                {
                    lbl_FAX番号.Text = "-";
                }
            }
            else
            {
                lbl_監理団体名.Text = "-";
                lbl_設立年月日.Text = "-";
                Label3.Text = "-";
                lbl_資本金.Text = "-";
                lbl_郵便番号.Text = "-";
                lbl_住所.Text = "-";
                lbl_電話番号.Text = "-";
                lbl_FAX番号.Text = "-";

            }
        }
        catch { }
        

    }

    public void Show本社情報()// show gridview.
    {
        try
        {
            本社情報Manager frm = new 本社情報Manager();
            本社情報 obj = new 本社情報();
            obj.企業ID = Int32.Parse(Session["企業コード_2"].ToString()); 
            DataTable dt = new DataTable();
            dt = frm.get_Grid本社情報(obj);
            if (dt.Rows.Count > 0)
            {
                grv.Visible = true;
                grv1.Visible = false;
                grv.DataSource = dt;
                grv.DataBind();
            }
            else
            {
                grv.Visible = false;
                grv1.Visible = true;
                AppCode_Common.ShowEmtyGrid<本社履歴>(grv1, 3, "データがありません。", "");
            }
        }
        catch { }
        //ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "regis", "Disable();", true);
    }

    protected void grv_PageIndexChanging(object sender, GridViewPageEventArgs e)// phan trang
    {
        grv.PageIndex = e.NewPageIndex;
        this.Show本社情報();
        //ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "regis", "Disable();", true);
        
    }

    public string ShowTextLength1(string temp)
    {
        //tieng viet
        if (temp.Length > 20)
            temp = temp.Substring(0, 20) + "...";
        if (temp.Length == 0)
        {
            temp = "";
        }
        return temp;

    }
   
}
